package com.sorhis.controller;

import com.sorhis.dto.SysMenuDTO;
import com.sorhis.dto.SysRoleDTO;
import com.sorhis.service.ISysMenuService;
import com.sorhis.service.ISysUserService;
import com.sorhis.vo.ResultVO;
import com.sorhis.vo.SysMenuTableVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xihao.ding
 * @since 2025-02-10
 */
@RestController
@RequestMapping("/sysMenu/v1")
@RequiredArgsConstructor
public class SysMenuController {

    private final ISysMenuService menuService;

    /**
     * 根据系统菜单信息查询菜单树
     * 此方法通过GET请求接收菜单信息参数，然后调用菜单服务的树形结构查询方法，
     * 将查询结果封装到ResultVO对象中返回给前端
     *
     * @param sysMenuDTO 系统菜单查询条件封装对象，包含菜单的必要信息
     * @return 返回包含菜单树数据的ResultVO对象
     */
    @GetMapping(value = "/tree")
    public ResultVO search(SysMenuDTO sysMenuDTO) {
        return ResultVO.ok(menuService.tree(sysMenuDTO));
    }

    @PostMapping(value = "/save")
    public ResultVO list(@RequestBody SysMenuDTO sysMenuDTO) {
        return ResultVO.ok(menuService.saveOrUpateDomain(sysMenuDTO));
    }

    @GetMapping("/list/table")
    public ResultVO listTable(SysMenuDTO sysMenuDTO){
        return ResultVO.ok(menuService.listTable(sysMenuDTO));
    }

    @PostMapping(value = "/del/{id}")
    public ResultVO del(@PathVariable String id) {
        return ResultVO.ok(menuService.del(id));
    }

    @GetMapping("/user")
    public ResultVO getMenusByUserId(@RequestParam(value = "userId") String userId ,
                                     @RequestParam(value = "accountType") Integer accountType ){
        return ResultVO.ok(menuService.getMenusByUserId(accountType == 1 ? null : userId));
    }


}
